import request from '@/config/axios'

export interface ProfileVO {
  id: number
  username: string
  nickname: string
  dept: {
    id: number
    name: string
  }
  roles: {
    id: number
    name: string
  }[]
  posts: {
    id: number
    name: string
  }[]
  socialUsers: {
    type: number
    openid: string
  }[]
  email: string
  mobile: string
  sex: number
  avatar: string
  status: number
  remark: string
  loginIp: string
  loginDate: Date
  createTime: Date
}

export interface UserProfileUpdateReqVO {
  nickname: string
  email: string
  mobile: string
  sex: number
}

// 查询用户个人信息
export const getUserProfile = () => {
  return request.get({ url: '/system/user/profile/get' })
}

// 修改用户个人信息
export const updateUserProfile = (data: UserProfileUpdateReqVO) => {
  return request.put({ url: '/system/user/profile/update', data })
}

// 用户密码重置
export const updateUserPassword = (oldPassword: string, newPassword: string) => {
  return request.put({
    url: '/system/user/profile/update-password',
    data: {
      oldPassword: oldPassword,
      newPassword: newPassword
    }
  })
}

// 用户头像上传
export const uploadAvatar = (data) => {
  return request.upload({
    url: 'https://api.geovisearth.com/passport/file/upload',
    data: data,
    ssoRequest: true
  })
}

// 获取用户信息
export const getuserInfo = () => {
  return request.get({
    url: 'https://api.geovisearth.com/passport/account/profile',
    ssoRequest: true
  })
}

// 获取用户微信
export const getThirdInfos = () => {
  return request.get({
    url: 'https://api.geovisearth.com/passport/account/getThirdInfos',
    ssoRequest: true
  })
}

// 保存用户信息
export const savePersonalUserInfo = (data) => {
  return request.post({
    url: 'https://api.geovisearth.com/passport/account/savePersonalUserInfo',
    data,
    ssoRequest: true
  })
}

// 验证手机号
export const checkAccount = (data) => {
  return request.post({
    url: 'https://api.geovisearth.com/passport/auth/checkAccount',
    data,
    ssoRequest: true
  })
}

// 发送验证码
export const sendSmsCode = (params) => {
  return request.get({
    url: 'https://api.geovisearth.com/passport/auth/sendSmsCode',
    params,
    ssoRequest: true
  })
}

// 绑定手机号
export const bindPhone = (data) => {
  return request.post({
    url: 'https://api.geovisearth.com/passport/account/bindPhone',
    data,
    ssoRequest: true
  })
}

// 验证手机号和验证码
export const verifyPhoneCode = (params) => {
  return request.get({
    url: 'https://api.geovisearth.com/passport/auth/verifyPhoneCode',
    params,
    ssoRequest: true
  })
}

// 更改手机号
export const changePhone = (data) => {
  return request.post({
    url: 'https://api.geovisearth.com/passport/account/changePhone',
    data,
    ssoRequest: true
  })
}

// 绑定第三方平台
export const bindThird = (data) => {
  return request.post({
    url: 'https://api.geovisearth.com/passport/account/bindThird',
    data,
    ssoRequest: true
  })
}

// 解绑第三方平台
export const unBindThird = (data) => {
  return request.post({
    url: 'https://api.geovisearth.com/passport/account/unBindThird',
    data,
    ssoRequest: true
  })
}

// 更新平台用户信息
export const updateUser = (data) => {
  return request.put({ url: '/system/user/updateTwo', data })
}
// 获取认证详情
export const getCertificationDetail = (params) => {
  return request.get({ url: 'https://cert.geovisearth.com/v1/ability/certification', params })
}
